package com.yituo.mjworld.mvc.action.codemonkey;

import com.yituo.mjworld.core.annotation.Dev;
import com.yituo.mjworld.core.annotation.NoToken;
import com.yituo.mjworld.mvc.entity.UserData;
import com.yituo.mjworld.core.utils.BaseDao;
import com.yituo.mjworld.core.web.core.MyHttpRequest;
import com.yituo.mjworld.core.web.core.MyHttpResponse;
import com.yituo.mjworld.mvc.entity.web.OtherToken;
import com.yituo.mjworld.mvc.entity.web.WebUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 当前组件中所有的接口仅用于测试登录
 *
 * @author xq
 */
@Component
public class SeeAction {

  @Autowired
  BaseDao baseDao;


  /**
   * 测试服务器是否可用
   *
   * @param req
   * @param res
   */
  @Dev
  @NoToken
  public void test(MyHttpRequest req, MyHttpResponse res) throws IOException {
    res.success(req.getCurrentUser());
  }

  /**
   * 查看当前用户列表
   *
   * @param req
   * @param res
   */
//  @Dev
  @NoToken
  public void seeToken(MyHttpRequest req, MyHttpResponse res) throws IOException {
    Map<String, OtherToken> map = UserData.getTokenMap();
    List<OtherToken> list = new ArrayList<OtherToken>();
    for (String i : map.keySet()) {
      list.add(map.get(i));
    }
    res.success(list);
  }

  /**
   * 查看当前Token列表
   *
   * @param req
   * @param res
   */
  @Dev
  @NoToken
  public void seeUser(MyHttpRequest req, MyHttpResponse res) throws IOException {
    Map<String, WebUser> map = UserData.getUserMap();
    List<WebUser> list = new ArrayList<WebUser>();
    for (String i : map.keySet()) {
      list.add(map.get(i));
    }
    res.success(list);
  }


}
